package com.sanyuan.cloud.spring.ai.ollama;

import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:  OllamaController
 * @Author: wuyuwei
 * @Date: 2025/4/25
 */
@RequestMapping("ollama")
@RestController
public class OllamaController {

    @Resource
    private ChatClient chatClient;

    @GetMapping("/chat")
    public String chat(@RequestParam("prompt") String prompt) {
        return chatClient.prompt()
                .user(prompt)
                .call()
                .content();
    }

    @GetMapping(value = "/chatFlux",produces = "text/html;Charset=UTF-8")
    public String chatFlux(@RequestParam("prompt") String prompt) {
        return chatClient.prompt()
                .user(prompt)
                .call()
                .content();
    }
}
